package service

import (
	"log"

	"example.com/m/v2/model/mysql"
	"gorm.io/gorm"
)

type User struct {
	BaseService
	db *gorm.DB
}

func NewUser(svcCtx *ServiceContext, db *gorm.DB) *User {
	res := User{db: db, BaseService: BaseService{svcCtx: svcCtx}}
	return &res
}

func (u *User) GetByUsername(username string) *mysql.User {
	var user mysql.User
	result := u.db.Where("username=?", username).First(&user)
	if result.Error != nil {
		log.Println(result.Error)
	}
	return &user
}
